package com.ztjy.purchase.biz.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ztjy.bean.CFirm;
import com.ztjy.purchase.biz.CFirmBiz;
import com.ztjy.purchase.dao.CFirmDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CFirmBizImpl implements CFirmBiz {
    @Autowired
    private CFirmDao fdao;

    @Override
    public List<CFirm> findAll(CFirm firm) {
        return fdao.findAll(firm);
    }


    @Override
    public PageInfo<CFirm> findCFirmPage(CFirm cFirm, Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo,pageSize);
        List<CFirm> all = fdao.findAll(cFirm);
        PageInfo<CFirm> cFirmPageInfo = new PageInfo<CFirm>(all);
        return cFirmPageInfo;
    }

    @Override
    public boolean updateCFirm(CFirm cFirm) {
        boolean flag = false;
        try {
            int row = fdao.updateByPrimaryKeySelective(cFirm);
            flag = (row != 0) ? true : false;
        } catch (Exception ex) {
            ex.printStackTrace();
            flag = false;
        }
        return flag;
    }

    @Override
    public boolean addCFirm(CFirm cFirm) {
        boolean flag = false;
        try {
            int row = fdao.insertSelective(cFirm);
            flag = (row != 0) ? true : false;
        } catch (Exception ex) {
            ex.printStackTrace();
            flag = false;
        }
        return flag;
    }

    @Override
    public CFirm findByIdCFirm(Integer id) {
        return fdao.findByIdCFirm(id);
    }

}
